﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using SpringStudio.Common;
using SpringStudio.DAL;

namespace Sdepci.InfoCode.BLL.CodeIndex
{
    /// <summary>
    /// 编码索引表
    /// </summary>
    public class Cate
    {
        #region 属性定义

        private string _cateGuid;
        /// <summary>
        /// 索引guid
        /// </summary>
        public string CateGuid
        {
            get { return this._cateGuid; }
        }

        private string _parentCateGuid;
        /// <summary>
        /// 父索引Guid
        /// </summary>
        public string ParentCateGuid
        {
            get { return this._parentCateGuid; }
        }

        private string _cateName;
        /// <summary>
        /// 索引名称
        /// </summary>
        public string CateName
        {
            get { return this._cateName; }
        }

        private string _cateDesc;
        /// <summary>
        /// 索引中文说明
        /// </summary>
        public string CateDesc
        {
            get { return this._cateDesc; }
        }

        private int _seq;
        /// <summary>
        /// 显示次序
        /// </summary>
        public int Seq
        {
            get { return this._seq; }
        }

        #endregion

        #region 构造方法

        public Cate(string cateGuid)
        {
            this._cateGuid = cateGuid;

            try
            {
                string sql = "Select CateGuid,ParentCateGuid,CateName,CateDesc,Seq From InfoCodeCates Where CateGuid=@CateGuid";
                DataSet ds = SqlHelper.ExecuteDataSet(ConnectionString.Default, CommandType.Text, sql,
                    SqlHelper.NewSqlParameter("@CateGuid", this._cateGuid));
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    DataRow row = ds.Tables[0].Rows[0];
                    this._cateGuid = row["CateGuid"].ToString();
                    this._parentCateGuid = row["ParentCateGuid"].ToString();
                    this._cateName = row["CateName"].ToString();
                    this._cateDesc = row["CateDesc"].ToString();
                    this._seq = int.Parse(row["Seq"].ToString());
                    
                }
                else
                {
                    throw new Exception("没有找到该值对应的详细记录！（参数：cateGuid'" + this._cateGuid + "'）");
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler.Handle(ex);
            }
        }

        public Cate(string cateGuid, string parentCateGuid, string cateName, string cateDesc, int seq)
        {
            this._cateGuid = cateGuid;
            this._parentCateGuid = parentCateGuid;
            this._cateName = cateName;
            this._cateDesc = cateDesc;
            this._seq = seq;
        }

        #endregion
    }
}
